<?php
namespace app\redis\controller;

use think\Controller;

class Sort extends Controller
{
	public $redis;
	
	public function __construct()
	{
		$this->redis = new \Redis();	
		$this->redis->connect('127.0.0.1',6379);	
	}
	
	public function zadd()
	{
		$this->redis->zAdd('report','1','张三');
		$this->redis->zAdd('report','2','李四');
		$this->redis->zAdd('report','36','王五');
		$this->redis->zAdd('report','38','赵六');
	}
	
	public function zadd2()
	{
		echo $this->redis->zadd('dongwu', 1, '猫');echo '<br>';
	 	echo $this->redis->zadd('dongwu', 2, '狗');echo '<br>';
		echo $this->redis->zadd('dongwu', 3, '鱼');echo '<br>';
	}
	
	public function zadd3()
	{
		echo $this->redis->zadd('dongwu', 1, '海豚');echo '<br>';
	}
	
	public function zadd4()
	{
		echo $this->redis->zadd('dongwu', 25, '河马');echo '<br>';
	}
	
	public function zrange()
	{
		$res = $this->redis->zRange('report','0',-1,true);
		//$re2 = $this->redis->zRange('report','0',-1,true);
		dump($res);
	}
	
	public function zrange2()
	{
		$res = $this->redis->zRange('dongwu',0,-1,true);
		dump($res);
	}
	
	public function zrem()
	{
		$this->redis->zRem('dongwu','骆驼','鱼','猴子','河马','鳄鱼','狗','猫','狮子','羊驼');
	}

	/**
	 * 统计元素个数
	 */
	public function zcard()
	{
		echo $this->redis->zCard('dongwu');
	}
	
	/**
	 * 用于计算有序集合中指定分数区间的成员数量
	 * O(log(N)+M)，N为有序集的基数，M为值在min和max之间的元素的数量。
	 * 1-4之间的成员个数，包括1和4
	 */
	public function zcount()
	{
		echo $this->redis->zCount('dongwu',1,24);
	}
	
	public function zscore()
	{
		dump($this->redis->zScore('dongwu','鱼'));
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}